

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

//import foodNhill.FoodDepot.VARIETIES;

import barricades.*;


public class Window extends JFrame implements ActionListener, WindowListener,ChangeListener{

	//public JPanel simulationArea;
	private JRadioButton jrAnthill, jrFeed, jrBarricades;
	private JSlider jsFeed, jsAnts;
	private JButton jbStart, jbBreak, jbContinue, jbNew,jbSettings, jbExit;
	private final 	Insets defaultIns = new Insets(2,2,2,2);
	private Menuebar mBar;
	
	
	/**
	 * Reihenfolge der Futterarten
	 */
	private final static FoodDepot.VARIETIES[] feed_depots={FoodDepot.VARIETIES.standard,FoodDepot.VARIETIES.apple,FoodDepot.VARIETIES.banana,FoodDepot.VARIETIES.meat};
	
	/**
	 * spezielle Slider zum Einstellen der Laenge der Barricaden bzw. der
	 * Ameisenperspective und der Futterstaerke mit festgelegten init-Werten
	 */
	private BarSlider jsDiag_left_right,jsDiag_right_left,jsHori,jsVerti;
	/**
	 * Label, die die Bilder aufnehmen
	 */
	private JLabel jlDiag_left_right,jlDiag_right_left,jlHori,jlVerti;
	
	/**
	 * JComboBox, die alle vorhandenen Futterdepots aufnimmt und das Aktive anzeigt
	 * sowie zum Anzeigen der Art des zusetzenden Futterdepots
	 */
	private JComboBox jcbAct,jcbDepots;
	/**
	 * Bilder fuer die Barricaden
	 */
	private ImageIcon iHori,iVerti,iDiag_right_left,iDiag_left_right;
	/**
	 * Button zum alternativen entfernen aktiver Futterhuegel
	 */
	private JButton jbDec;
	
	/**
	 * RadioButton zur Auswahl der gewuenschten Barricaden
	 */
	private JRadioButton jrHori,jrVerti,jrDiag_right_left,jrDiag_left_right;
	/**
	 * ButtonGroup fuer die Barrikaden
	 */
	private ButtonGroup bg;
	/**
	 * zum An-und Abwaehlen des Increase-Modes von Futterhuegeln
	 */
	private JCheckBox jcIncMode;
	/**
	 * Anzahl wie viele Futterdepots aktuell vorhanden sind
	 */
	private int active_depot_counter;
	
	/**
	 * Hilfsvariable die zum Entfernen der Futterdepots gebraucht wird
	 */
	private boolean removing;
	
	/**
	 * Runnable das den Thread in dem simuliert wird kontrolliert
	 */
	private Simulation simulationThread;
	
	/**
	 * JSlider finals - Variablen zum Einrichten der JSlider
	 */
	public static final int ANTS_MIN=160,ANTS_MAX=1760,ANTS_INIT=960,MINOR_TICK=80,MAJOR_TICK=400, 
	 FEED_MIN=20,FEED_MAX=100,FEED_INIT=60, FEED_MAJOR_TICK=20,FEED_MINOR_TICK=5;
	/**
	 * die AntSimulation auf die sich das Window bezieht
	 */
	private AntSimulation antSim;
	
	/**
	 * Konstruktor der die grundlegenen GUI-Komponenten anlegt
	 * @param as
	 */
	public Window(AntSimulation as){
		super("Ant Simulation");
	
		antSim=as;
		int w=antSim.getSimWidth();
		int h=antSim.getSimHeight();
		
		active_depot_counter=0;
		load_images();
		
		mBar=new Menuebar(antSim);
		this.setJMenuBar(mBar);
		this.simulationThread=new Simulation(antSim);
		
		GridBagLayout gb = new GridBagLayout();
			this.setLayout(gb);
		GridBagConstraints c = new GridBagConstraints();
		
			c.insets =  defaultIns;
			c.anchor=GridBagConstraints.FIRST_LINE_START;
			
		JLabel jlForest = new JLabel("forest ground");
				gb.setConstraints(jlForest, c);
			this.add(jlForest);
			

				antSim.getSimArea().setBackground(AntSimulation.bgColor);
				antSim.getSimArea().setPreferredSize(new Dimension(w,h));
			
					c.gridheight=9;
					c.gridy=1;
					gb.setConstraints(antSim.getSimArea(), c);
			this.add(antSim.getSimArea());
		
		JLabel jlInputMode = new JLabel("input mode:");
				c.gridx=1;
				c.gridheight=1;
				gb.setConstraints(jlInputMode, c);
			this.add(jlInputMode);
			
		jrAnthill = new JRadioButton("anthill",true);
				c.gridy=2;
				gb.setConstraints(jrAnthill, c);
			this.add(jrAnthill);
			
		jrFeed = new JRadioButton("feed");
				c.gridy=3;
				gb.setConstraints(jrFeed, c);
			this.add(jrFeed);
			
		jrBarricades = new JRadioButton("barricades");
				c.gridy=4;
				gb.setConstraints(jrBarricades, c);
			this.add(jrBarricades);	
	
			ButtonGroup bgControl = new ButtonGroup();		
				bgControl.add(jrAnthill);
				bgControl.add(jrFeed);
				bgControl.add(jrBarricades);
			
		JLabel jlNumberAnts = new JLabel("total number of ants:");
				c.gridy=7;
				gb.setConstraints(jlNumberAnts, c);
			this.add(jlNumberAnts);
			
		jsAnts = new JSlider(ANTS_MIN,ANTS_MAX,ANTS_INIT);
				jsAnts.setMajorTickSpacing(MAJOR_TICK);
				jsAnts.setMinorTickSpacing(MINOR_TICK);
				jsAnts.setPaintTicks(true);
				jsAnts.setPaintLabels(true);
				jsAnts.setSnapToTicks(true);
				jsAnts.addChangeListener(this);
					c.gridy=8;
					gb.setConstraints(jsAnts, c);
			this.add(jsAnts);	
		
		JPanel jpButtons = new JPanel();
			makeButtonPanel(jpButtons);
					c.gridy=9;
					c.anchor=GridBagConstraints.PAGE_END;
					gb.setConstraints(jpButtons, c);
				this.add(jpButtons);	
				
		JPanel jpBarFeed = new JPanel();
			makeBarAndFeedPanel(jpBarFeed);
					c.gridy=0;
					c.gridx=3;
					c.gridheight=11;
					c.anchor=GridBagConstraints.PAGE_START;
					gb.setConstraints(jpBarFeed, c);
				this.add(jpBarFeed);			
				
					bg=new ButtonGroup();
						bg.add(jrDiag_left_right);
						bg.add(jrDiag_right_left);
						bg.add(jrHori);
						bg.add(jrVerti);					
				
				
		this.setResizable(false);		
		this.addWindowListener(this);
		//this.setSize(new Dimension(w+580,h+110));
		this.pack();
		Start.setIcon(this);
		this.setVisible(true);
	
	}//constructor
	
	/**
	 * Einrichten und Anordnen der Buttons auf einem Panel
	 * @param jpButtons
	 */
	private void makeButtonPanel(JPanel jpButtons){
		
		Dimension dButton = new Dimension(100,20);
		
		GridBagLayout gbButtons = new GridBagLayout();
			jpButtons.setLayout(gbButtons);
		GridBagConstraints cButtons = new GridBagConstraints();
			cButtons.insets = defaultIns;
			cButtons.anchor=GridBagConstraints.LINE_START;
			
		jbStart = new JButton("start");
			jbStart.setPreferredSize(dButton);
			jbStart.addActionListener(this);
					gbButtons.setConstraints(jbStart, cButtons);
				jpButtons.add(jbStart);
			
		jbBreak = new JButton("break");	
			jbBreak.setPreferredSize(dButton);
			jbBreak.setEnabled(false);
			jbBreak.addActionListener(this);
					cButtons.gridy=1;
					gbButtons.setConstraints(jbBreak,cButtons);
				jpButtons.add(jbBreak);
			
		jbContinue = new JButton("continue");	
			jbContinue.setPreferredSize(dButton);
			jbContinue.setEnabled(false);
			jbContinue.addActionListener(this);
					cButtons.gridx=1;
					gbButtons.setConstraints(jbContinue,cButtons);
				jpButtons.add(jbContinue);		
		
		jbNew = new JButton("new");	
			jbNew.setPreferredSize(dButton);
			jbNew.addActionListener(this);
					cButtons.gridy=2;
					cButtons.gridx=0;
					gbButtons.setConstraints(jbNew,cButtons);
				jpButtons.add(jbNew);
		
		jbSettings = new JButton("reset");	
			jbSettings.setPreferredSize(dButton);
			jbSettings.addActionListener(this);
					cButtons.gridx=1;
					gbButtons.setConstraints(jbSettings,cButtons);
				jpButtons.add(jbSettings);				
				
		jbExit = new JButton("exit");
			jbExit.setPreferredSize(dButton);
			jbExit.addActionListener(this);
					cButtons.gridy=3;	
					gbButtons.setConstraints(jbExit,cButtons);
				jpButtons.add(jbExit);		
				
	}//makeButtonPanel

	/**
	 * Einrichten und Anordnen der Menupunkte BARRICADES und FEED DEPOTS auf einem Panel
	 * @param jpBarFeed
	 */
	private void makeBarAndFeedPanel(JPanel jpBarFeed){
		
		GridBagLayout gbBarFeed = new GridBagLayout();
		jpBarFeed.setLayout(gbBarFeed);
		GridBagConstraints cBarFeed = new GridBagConstraints();
		cBarFeed.insets = defaultIns;
		//cBarFeed.anchor=GridBagConstraints.LINE_START;
		
		//Insets iButton=new Insets(2,20,2,20);
		Insets iDefault=new Insets(2,2,2,2);
		
		//barricades
		
		JLabel jlBars=new JLabel("BARRICADES");
			cBarFeed.insets=iDefault;
			cBarFeed.gridwidth=3;
			cBarFeed.anchor=GridBagConstraints.LINE_START;
			gbBarFeed.setConstraints(jlBars, cBarFeed);
			jpBarFeed.add(jlBars);
		
		cBarFeed.anchor=GridBagConstraints.CENTER;
		cBarFeed.gridy=1;
		cBarFeed.gridwidth=1;
		
		jrHori=new JRadioButton("",true);
		gbBarFeed.setConstraints(jrHori, cBarFeed);
		jpBarFeed.add(jrHori);
		
		
		jrVerti=new JRadioButton("");
			cBarFeed.gridy=2;
			gbBarFeed.setConstraints(jrVerti, cBarFeed);
			jpBarFeed.add(jrVerti);
		
		
		jrDiag_left_right=new JRadioButton("");
			cBarFeed.gridy=3;
			gbBarFeed.setConstraints(jrDiag_left_right, cBarFeed);
			jpBarFeed.add(jrDiag_left_right);
		
		
		jrDiag_right_left=new JRadioButton("");
			cBarFeed.gridy=4;
			gbBarFeed.setConstraints(jrDiag_right_left, cBarFeed);
			jpBarFeed.add(jrDiag_right_left);
		
		jlHori = new JLabel();
		jlHori.setIcon(iHori);
			cBarFeed.gridy=1;
			cBarFeed.gridx=1;
			gbBarFeed.setConstraints(jlHori, cBarFeed);
			jpBarFeed.add(jlHori);
		
		
		jlVerti=new JLabel();
		jlVerti.setIcon(iVerti);
			cBarFeed.gridy=2;
			gbBarFeed.setConstraints(jlVerti, cBarFeed);
			jpBarFeed.add(jlVerti);
	
		
		jlDiag_left_right=new JLabel();
		jlDiag_left_right.setIcon(iDiag_left_right);
			cBarFeed.gridy=3;
			gbBarFeed.setConstraints(jlDiag_left_right, cBarFeed);
			jpBarFeed.add(jlDiag_left_right);
		
		jlDiag_right_left=new JLabel();
		jlDiag_right_left.setIcon(iDiag_right_left);
			cBarFeed.gridy=4;
			gbBarFeed.setConstraints(jlDiag_right_left, cBarFeed);
			jpBarFeed.add(jlDiag_right_left);
		
			//important
			cBarFeed.gridwidth=4;
		
		jsHori=new BarSlider();
			cBarFeed.gridx=2;
			cBarFeed.gridy=1;
			gbBarFeed.setConstraints(jsHori, cBarFeed);
			jpBarFeed.add(jsHori);
			
			
		jsVerti=new BarSlider();
			cBarFeed.gridy=2;
			gbBarFeed.setConstraints(jsVerti, cBarFeed);
			jpBarFeed.add(jsVerti);
		
		jsDiag_left_right=new BarSlider();
			cBarFeed.gridy=3;
			gbBarFeed.setConstraints(jsDiag_left_right, cBarFeed);
			jpBarFeed.add(jsDiag_left_right);
		
		
		jsDiag_right_left=new BarSlider();
			cBarFeed.gridy=4;
		
			gbBarFeed.setConstraints(jsDiag_right_left, cBarFeed);
			jpBarFeed.add(jsDiag_right_left);
		
		//food
		JLabel jlFood=new JLabel("FEED DEPOTS");
			cBarFeed.gridy=5;
			cBarFeed.gridx=0;
			
			cBarFeed.anchor=GridBagConstraints.LINE_START;
			gbBarFeed.setConstraints(jlFood, cBarFeed);
			jpBarFeed.add(jlFood);
		
		cBarFeed.insets=iDefault;
		cBarFeed.gridwidth=1;
		//cBarFeed.anchor=GridBagConstraints.CENTER;	
		
		JLabel jlnumber=new JLabel("number:");
			cBarFeed.gridy=6;
			cBarFeed.gridx=1;
			gbBarFeed.setConstraints(jlnumber, cBarFeed);
			jpBarFeed.add(jlnumber);
			
			
			//alternate version with inc mode and klick
		jcIncMode=new JCheckBox("increase mode");
			cBarFeed.gridx=2;
			gbBarFeed.setConstraints(jcIncMode, cBarFeed);
			jpBarFeed.add(jcIncMode);
			
		jbDec=new JButton("--");
			jbDec.setPreferredSize(new Dimension(50,20));
			jbDec.addActionListener(this);
			cBarFeed.gridx=3;
			gbBarFeed.setConstraints(jbDec, cBarFeed);
			jpBarFeed.add(jbDec);	
			
				
		JLabel jlAct=new JLabel("active depot:");
			cBarFeed.gridy=8;
			cBarFeed.gridx=1;
			cBarFeed.gridwidth=1;
			gbBarFeed.setConstraints(jlAct, cBarFeed);
			jpBarFeed.add(jlAct);
			
		jcbAct = new JComboBox();
			jcbAct.setPreferredSize(new Dimension(100,20));
			jcbAct.addActionListener(this);
			cBarFeed.gridx=2;
			cBarFeed.anchor=GridBagConstraints.CENTER;
			cBarFeed.gridwidth=4;
			gbBarFeed.setConstraints(jcbAct, cBarFeed);
			jpBarFeed.add(jcbAct);
			
		
		JLabel jlDepotVariety =new JLabel("variety:");
			cBarFeed.gridwidth=1;
			cBarFeed.gridx=1;
			cBarFeed.anchor=GridBagConstraints.LINE_START;
			cBarFeed.gridy=9;
			gbBarFeed.setConstraints(jlDepotVariety, cBarFeed);
			jpBarFeed.add(jlDepotVariety);
			
			
			
		jcbDepots = new JComboBox(feed_depots);
		jcbDepots.setPreferredSize(new Dimension(100,20));
		jcbDepots.addActionListener(this);
		cBarFeed.gridx=2;
		cBarFeed.anchor=GridBagConstraints.CENTER;
		cBarFeed.gridwidth=4;
		gbBarFeed.setConstraints(jcbDepots, cBarFeed);
		jpBarFeed.add(jcbDepots);	
			
		
		JLabel jlSizeFeed = new JLabel("size:");
		cBarFeed.gridy=10;
		cBarFeed.gridx=1;
		cBarFeed.gridwidth=1;
	//	cBarFeed.gridheight=2;
		cBarFeed.anchor=GridBagConstraints.LINE_START;
		//c.insets = new Insets(10,2,2,2);
		gbBarFeed.setConstraints(jlSizeFeed, cBarFeed);
	jpBarFeed.add(jlSizeFeed);	
	
jsFeed = new JSlider(FEED_MIN,FEED_MAX,FEED_INIT);
		jsFeed.setMajorTickSpacing(FEED_MAJOR_TICK);
		jsFeed.setMinorTickSpacing(FEED_MINOR_TICK);
		jsFeed.setPaintLabels(true);
		jsFeed.setPaintTicks(true);
		jsFeed.setSnapToTicks(true);
		jsFeed.addChangeListener(this);
			cBarFeed.gridheight=2;
			cBarFeed.gridx=2;
			cBarFeed.gridwidth=4;
			//cBarFeed.insets= defaultIns;
			gbBarFeed.setConstraints(jsFeed, cBarFeed);
	jpBarFeed.add(jsFeed);
		
		jpBarFeed.setBorder(BorderFactory.createEtchedBorder());
			
	}
	
	
	
	
	/**
	 * laedt die die Bilder zur Darstellung der verschiedenen Barricades
	 */
	private void load_images(){
	
		try{
			iHori =new ImageIcon(ImageIO.read(getClass().getResourceAsStream("images/horizontal.gif")));
			iVerti =new ImageIcon(ImageIO.read(getClass().getResourceAsStream("images/vertical.gif")));
			iDiag_left_right =new ImageIcon(ImageIO.read(getClass().getResourceAsStream("images/diagonal_left_to_right.gif")));
			iDiag_right_left =new ImageIcon(ImageIO.read(getClass().getResourceAsStream("images/diagonal_right_to_left.gif")));
		
		}catch(Exception e){
			System.out.println("Failed to load images.");
		}
  
	}//load_images();
	
	/**
	 * gibt zurueck welche VARIETY grade ausgewaehlt ist
	 * @return
	 */
	public FoodDepot.VARIETIES getFeedVariety(){
		return (FoodDepot.VARIETIES)jcbDepots.getSelectedItem();
	}
	
	/**
	 * @return die aktuelle Anzahl der Futterdepots
	 */
	
	public int getNumberOfDepots(){
		return jcbAct.getItemCount();
	}
	
	/**
	 * 
	 * @return der Index des z.Zt. ausgewaehlten Futterdepots
	 */
	public int getActiveDepot(){
		return jcbAct.getSelectedIndex();
	}
	
	/**
	 * erhoeht die Anzahl der Futterdepots um 1
	 */
	public void incFeedDepot(){
		active_depot_counter++;
		jcbAct.addItem("depot: "+active_depot_counter);
	}
	
	/**
	 * waehlt ein Futterdepot als aktiv aus
	 * @param number die Nummer des auszuwaehlenden Futterdepots
	 */
	public void setActive(int number){
		jcbAct.setSelectedIndex(number);
	}

	/**
	 * schaut ob der Modus, das mehrere Futterdepots gesetzt werden koennen
	 * ausgewaehlt ist oder ob der aktuelle Futterhuegel versetzt werden soll
	 * @return true, wenn man mehr als ein Futterdepot setzen kann
	 */
	public boolean isIncMode(){
		return jcIncMode.isSelected();
	}
	
	/**
	 * entfernt das aktive Futterdepot
	 */
	public void removeFeedDepot(){
		if(jcbAct.getSelectedIndex()>=0){
			removing=true;
			antSim.removeFeedDepot(jcbAct.getSelectedIndex());
			active_depot_counter--;
			jcbAct.removeAllItems();
			for(int i=1;i<=active_depot_counter;i++){
				jcbAct.addItem("depot: "+i);
			
			}
			removing=false;
		}
	}
	
	/**
	 * erzeugt einen neue Barricade entsprechend den ausgewaehlten Einstellungen
	 * (also welcher Typ angewaehlt ist und wie lang die Barricade sein soll)
	 * @param p Mittelpunkt der zu setzenden Barricade
	 * @return die neu erschaffene Barricade
	 */
	public Barricade getSelectedBarricade(Point p){
		if(jrHori.isSelected()){
			return new HorizontalBarricade(p,jsHori.getValue());
		}else if(jrVerti.isSelected()){
			return new VerticalBarricade(p,jsVerti.getValue());
		}else if(jrDiag_left_right.isSelected()){
			return new BottomDiagBarricade(p,jsDiag_left_right.getValue());
		}else {
			return new TopDiagBarricade(p,jsDiag_right_left.getValue());
		}
	}//getSelectedBarricade()
	
	
	
	/*
	 * getter
	 */
	/**
	 * gibt den Wert des 'total number of ants'-Schiebereglers zurueck
	 */
	public int getNumberOfAnts(){
		return jsAnts.getValue();
	}
	
	/**
	 * gibt den Wert des size-Schiebereglers unter Feed Depots zurueck
	 * @return
	 */
	public int getSizeFeed(){
		return jsFeed.getValue();
	}
	
	/**
	 * gibt zurueck, ob grade Futterdepots gesetzt werden sollen
	 * @return true, wenn der input mode feed ist
	 */
	public boolean isFeed(){
		return jrFeed.isSelected();
	}
	
	/**
	 * gibt zurueck, ob grade der Ameisenhaufen gesetzt werden soll
	 * @return true, wenn der input mode anthill ist
	 */
	public boolean isAnthill(){
		return jrAnthill.isSelected();
	}
	
	/**
	 * gibt zurueck, ob grade Barrikaden gesetzt werden sollen
	 * @return true, wenn der input mode barricades ist
	 */
	public boolean isBarricades(){
		return jrBarricades.isSelected();
	}
	
	//*****NEW**********little Helper
	/**
	 * Zusammenfassung der (De-)Enabelung von Buttons
	 */
	public void guiEnabler(boolean enabled){
		jbContinue.setEnabled(enabled);
		jbNew.setEnabled(enabled);
		jbSettings.setEnabled(enabled);
		jbBreak.setEnabled(!enabled);
		jbDec.setEnabled(enabled);
	}//guiEnabler()
	
	/*
	 * Listener-Methoden
	 */
	
	public void actionPerformed(ActionEvent aEv) {
		Object source = aEv.getSource();
		
		if(source==jbDec){
			removeFeedDepot();
		}
		else if(source==jcbAct){
			if(active_depot_counter!=0){
				if(!removing){
				FoodDepot  fd=antSim.getDepot(jcbAct.getSelectedIndex());
				jcbDepots.setSelectedItem(fd.getType());
				jsFeed.setValue(fd.size);
				}
			}
		}
		else if(source==jcbDepots){
			if(active_depot_counter!=0)			
				antSim.updateRectangle(2);
			
		}
		else if(source==jbStart){
			
			if(antSim.isCorrectlySet()){
				antSim.setStarted(true);
			
			//gui handler
			jbStart.setEnabled(false);
				guiEnabler(false);
			
			jsAnts.setEnabled(false);
			jsFeed.setEnabled(false);
			
			antSim.initialzeSimulation();

			simulationThread.start_new_simulation();
			}
			else{
				JOptionPane.showMessageDialog(this, "Missing Information. Please set feed and anthill correctly" +
						"\n- they should not interlapse or be out of the simulation box.");
			}

		}else if(source==jbBreak){
			
			guiEnabler(true);
			
			simulationThread.interrupt_simulation();
			
		}else if(source==jbContinue){
			
			guiEnabler(false);
			
			simulationThread.continue_simulation();
			
		}else if(source==jbNew){	
			
			simulationThread.exit_Simulation();
		
			antSim.getWindow().dispose();
			Start.startProgram();
			
		}else if(source==jbSettings){
		
			simulationThread.exit_Simulation();
			
			jbStart.setEnabled(true);
			jbContinue.setEnabled(false);
			jbBreak.setEnabled(false);
			
			jsAnts.setEnabled(true);
			jsFeed.setEnabled(true);
			
			antSim.newSettings();
			
		}else if(source==jbExit){
		
			simulationThread.exit_Simulation();
			
			System.exit(0);
		}
		
	}//actionPerformed(ActionEvent aEV)

	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void windowClosing(WindowEvent e) {
		System.exit(0);
	}

	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void windowDeiconified(WindowEvent e) {
		antSim.setWasMinimized(true);
	//	antSim.revalidateForestGround();
		
	}

	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void stateChanged(ChangeEvent cEv) {
		Object source=cEv.getSource();
		if(source ==jsAnts){
			antSim.updateRectangle(1);
		}
		else if(source == jsFeed){
			if(active_depot_counter!=0)
				antSim.updateRectangle(2);
		}
		
	}
	


}//class Window
